<template>
    <div>
        <h1>添加会员权益</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>会员权益名称</td>
                    <td><input type="text" v-model="info.huiYuanQYName"></td>
                </tr>
                <tr>
                    <td>会员权益状态</td>
                    <td><input type="radio" v-model="info.huiYuanQYStare" value="1">启用
                        <input type="radio" v-model="info.huiYuanQYStare" value="0">禁用
                       
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <button @click="AddHuiYuanqy">修改</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
 let info: any = reactive({
    id: route.query.id,
    huiYuanQYName: '',
  huiYuanQYStare: '',
  
});
onMounted(() => {
   funer(); 
})
const AddHuiYuanqy=()=>{
    if(info.huiYuanQYName==''){
        alert('请输入会员权益名称')
        return;
    }
    if(info.huiYuanQYStare==''){
        alert('请选择会员权益状态')
        return; 
    }
    axios({
        url: '/api/HuiYuan/HyQyUpdate',
        method: 'put',
        data: info
    }) 
   .then((res)=>{
       if(res.data=1){
          alert('修改成功')
           router.push('/ShowHuiYuanQy');
          

       }
       else{
           alert('修改失败')
           return;
           
       }
    }) 
  .catch((err)=>{
      console.log(err); 
  })
}
const funer=()=>{
    axios({
        url: '/api/HuiYuan/QyFune',
        method: 'get',
        params: { id: route.query.id }
    }) 
 .then((res)=>{
  info.huiYuanQYName=res.data.huiYuanQYName;
  info.huiYuanQYStare=res.data.huiYuanQYStare;
  console.log(info); 
 })
.catch((err)=>{
      console.log(err);
  }) 

}

</script>

<style scoped>

</style>